home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / ka9q / ka9q_src.arc / TCPDUMP.C < prev    next >
C/C++ Source or Header  |  1988-07-28  |  1KB  |  63 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "netuser.h"
  5. #include "internet.h"
  6. #include "timer.h"
  7. #include "tcp.h"
  8. #include "trace.h"
  9.  
  10. /* TCP segment header flags */
  11. char *tcpflags[] = {
  12.     "FIN",    /* 0x01 */
  13.     "SYN",    /* 0x02 */
  14.     "RST",    /* 0x04 */
  15.     "PSH",    /* 0x08 */
  16.     "ACK",    /* 0x10 */
  17.     "URG"    /* 0x20 */
  18. };
  19.  
  20. /* Dump a TCP segment header. Assumed to be in network byte order */
  21. void
  22. tcp_dump(bpp,source,dest,check)
  23. struct mbuf **bpp;
  24. int32 source,dest;    /* IP source and dest addresses */
  25. int check;        /* 0 if checksum test is to be bypassed */
  26. {
  27.     int i;
  28.     struct tcp seg;
  29.     struct pseudo_header ph;
  30.     int16 csum;
  31.  
  32.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  33.         return;
  34.  
  35.     /* Verify checksum */
  36.     ph.source = source;
  37.     ph.dest = dest;
  38.     ph.protocol = TCP_PTCL;
  39.     ph.length = len_mbuf(*bpp);
  40.     csum = cksum(&ph,*bpp,ph.length);
  41.  
  42.     ntohtcp(&seg,bpp);
  43.  
  44.     printf("TCP: %u->%u Seq x%lx",seg.source,seg.dest,seg.seq,seg.ack);
  45.     if(seg.flags & ACK)
  46.         printf(" Ack x%lx",seg.ack);
  47.     for(i=0;i<6;i++){
  48.         if(seg.flags & 1 << i){
  49.             printf(" %s",tcpflags[i]);
  50.         }
  51.     }
  52.     printf(" Wnd %u",seg.wnd);
  53.     if(seg.flags & URG)
  54.         printf(" UP x%x",seg.up);
  55.     /* Print options, if any */
  56.     if(seg.mss != 0)
  57.         printf(" MSS %u",seg.mss);
  58.     if(check && csum != 0)
  59.         printf(" CHECKSUM ERROR (%u)",i);
  60.     printf("\n");
  61. }
  62.  
  63.